var { getLoginedUser, formatTime,fnLoading, fnHideLoading, fnSuccess, fnFail } = require('../../utils/index')
import { domainStatic } from '../../utils/env.js';
import _ from '../../utils/underscore.js';
import { get, fnChoose, lsGetStr, fnUpload, post } from '../../utils/request.js';
// pages/commission/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
other:{},
    history:[],//佣金历史记录
price:"",
apy:""
  },

click:function(){
  let that=this;
  var money=that.data.other.now;
  if(money<100){
    fnFail ("佣金余额小于100，无法提现");
  }else{
    that.setData({
      price:money,
    });
    wx.navigateTo({
      url: '../withdraw/index?type='+that.data.price,
    })
  }
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    fnLoading('加载中...');
    getLoginedUser()
    .then(function(user){
      return Promise.all([
        get({
          path: "/user/commission"
        }),
        get({
          path: "/user/history/commission?type1=commission-withdraw&pId=" + user.id
        }),
      ])
    })
     
      .then(function(res){
        fnHideLoading()
        let commission = res[0],
          history = res[1].map(function(item){
            item.createAt = (item.validEnd ? formatDate(item.validEnd):formatTime(new Date()))
            return item;
          })
  that.setData({
    other: commission,
    history: history,
  })
})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

})